package com.znsd.zl.app.customize.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.znsd.zl.app.customize.dao.CustomizeDao;
import com.znsd.zl.app.customize.entity.CustomizeEntity;
import com.znsd.zl.app.customize.service.CustomizeService;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


/**
 * @ClassName TCustomize
 * @Description 描述
 * @author zhangzhou
 * @email jaypdd@163.com
 * @date 2020-08-30 15:42:52
 * @Version v1.0
 */
@Service("customizeService")
public class CustomizeServiceImpl extends ServiceImpl<CustomizeDao, CustomizeEntity> implements CustomizeService {

	@Override
	public boolean save(CustomizeEntity entity) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String format = df.format(new Date());
		entity.setUpdateTime(format);
		CustomizeEntity byName = baseMapper.findByName(entity.getUserName());
		if (byName==null){
			entity.setCreateTime(format);
			baseMapper.insert(entity);
		}
		else{
			entity.setStatus(0);
			entity.setId(byName.getId());
			System.out.println("-------------");
			System.out.println(entity);

			baseMapper.updateById(entity);
		}
		return true;
	}

	@Override
	public boolean updateById(CustomizeEntity entity) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String format = df.format(new Date());
		entity.setCreateTime(format);
		baseMapper.updateById(entity);
		return true;
	}

	@Override
	public boolean setStatusSuccess(Integer id) {
		baseMapper.setStatusSuccess(id);
		return true;
	}

	@Override
	public boolean setStatusCancel(String name) {
		baseMapper.setStatusCancel(name);
		return true;
	}

	@Override
	public CustomizeEntity findByName(String name) {
		CustomizeEntity byName = baseMapper.findByName(name);
		if (byName==null){
			return null;
		}
		return byName;
	}

	@Override
	public void isDelete(Integer id) {
		baseMapper.isDelete(id);
	}

	@Override
	public <E extends IPage<CustomizeEntity>> E page(E page, Wrapper<CustomizeEntity> queryWrapper) {

		System.out.println("进入了。。。。。");
		QueryWrapper<CustomizeEntity> wrapper = new QueryWrapper<>();
		wrapper.eq("is_delete",0);
		return baseMapper.selectPage(page,wrapper);
	}



}
